<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>部门管理</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
<style>
* {
	font-size: 12px;
}
.item {
	margin-top: 5px;
}
</style>
	<script type="text/javascript">
		$(function() {
			//打开窗口
			$("#dept-add").linkbutton({
				onClick : function() {
					$('#win-dept').window({
						'title' : "录入信息"
					});
					$("#win-dept").window("open");
				}
			});

			//添加
			$("#btn-ok").linkbutton({
				onClick : function() {
					var title = $('#win-dept').window("options").title;
					var url = (title == '录入信息' ? 'addDept' : 'editDept');
					$("#form-deptadd").form('submit', {
						url : url,
						onSubmit : function() {
							//验证
							return $(this).form("validate");
						},
						success : function(data) {
							var json = eval("(" + data + ")");
							$.messager.alert("提示", json.reason);
							//关闭窗口
							$('#win-dept').window('close');
							//重新加载数据
							$("#tb-dept").datagrid("reload");
						}
					});
				}
			});

			//修改信息
			$("#dept-edit").linkbutton(
					{
						onClick : function() {
							var rows = $("#tb-dept").datagrid("getSelections");
							if (rows.length == 1) {
								$('#win-dept').window({
									'title' : "修改信息"
								});
								$('#win-dept').window("open");
								//初始化表单
								var bmNo = rows[0].bmNo;
								$.getJSON("findDeptById", {
									"bmNo" : bmNo
								}, function(data) {
									$("#form-deptadd").form("load", data);
								});
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ rows.length + "条!");
							}
						}
					});

			$("#btn-cancel").linkbutton({
				onClick : function() {
					$('#win-dept').window('close');
				}
			});

			//删除
			$("#dept-del").linkbutton({
				onClick : function() {
					$.messager.confirm("提示", "确定要删除吗？", function(v) {
						if (v) {
							//获取所有选中的编号
							var rows = $("#tb-dept").datagrid("getSelections");
							//将编号保存到数组中
							var arr = [];
							for (var i = 0; i < rows.length; i++) {
								arr.push(rows[i].bmNo);
							}
							//用form提交
							$('<form>').form('submit', {
								url : 'delDeptBatch',
								onSubmit : function(param) {
									param.list = arr;
								},
								success : function(data) {
									var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$("#tb-dept").datagrid("reload");
								}
							});
						}
					});
				}
			});
			
		   //查看员工信息
			$("#emp-all").linkbutton({
				onClick : function() {
					var rows = $("#tb-dept").datagrid("getSelections");
					if(rows.length==1){
						$('#bmemp').window('open');
						var bmNo = rows[0].bmNo
						var url = "findByEmpAll?bmNo="+bmNo;
						$('#tb-depts').datagrid({  
						    url:url,  
						});
					}
					else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了"
								+ rows.length + "条!");
					}
				}
			});
		   
		});
	</script>
	<table id="tb-dept" class="easyui-datagrid"
		data-options="url:'queryAllDept',
		 fitColumns:true,
		 fit:true,
         pagination:true,     
         rownumbers:true,
		 toolbar:'#dept',
		 fitColumn: false,
		 border: false
	    ">
		<thead>
			<tr>
				<th class="drag-item" data-options="field:'bmNo',width:'5%', checkbox: true">编号</th>
				<th class="drag-item" data-options="field:'bmName',width:'10%'">名称</th>
				<th class="drag-item" data-options="field:'bmLocation',width:'15%'">位置</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	
	<div id="dept">
		<a id="dept-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a> 
		<a id="dept-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
		<a id="emp-all"class="easyui-linkbutton" data-options="iconCls:'icon-emplook',plain:true">查看信息 </a>
		<a id="dept-del" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除</a> 
	</div>

	<!-- 打开窗口 -->
	<div id="win-dept" class="easyui-window" title="录入信息" 
	     data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		 style="width: 300px; height: 200px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="form-deptadd" method="post">
					<div class="item">
						部门编号&nbsp;<input name="bmNo" class="easyui-textbox" value="${autoId}" data-options="width: 100" /></div>
					<div class="item">
						部门名称&nbsp;<input name="bmName" class="easyui-textbox" data-options="width: 140" /></div>
					<div class="item">
						部门位置&nbsp;<input name="bmLocation" class="easyui-textbox" data-options="width: 140" /></div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align: right; padding: 5px 0 0;">
				<a id="btn-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true">确定</a> 
				<a id="btn-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#win-dept').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
    
    <!--根据部门编号查看信息  -->
	<div id="bmemp" class="easyui-window"  data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,closed: true,title:'查看信息'">
		<table id="tb-depts" class="easyui-datagrid" data-options="width: 460,height: 300,fitColumns:true">
			<thead>
				<tr>
					<th data-options="field:'ygName',width:'20%'">姓名</th>
					<th data-options="field:'ygSex',width:'14%'">性别</th>
					<th data-options="field:'ygTel',width:'26%'">联系电话</th>
					<th data-options="field:'ygServiceState',width:'14%'">在职状态</th>
					<th data-options="field:'ygEntryDate',width:'26%'">入职时间</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>

</body>
</html>